home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-06-15 | 2.9 KB | 141 lines | [TEXT/MMCC] |
- // ===========================================================================
- // SCApp.cp
- // ===========================================================================
- // © 1995 James Kaput, Jeremy Roschelle SimCalc Project
-
- #include "SCApp.h"
- #include "SCDoc.h"
- #include "SCModelProperty.h"
- #include "SCFinderUtility.h"
- #include "SCScriptsMenu.h"
-
- long SCApp::sUniqueID = 100;
- SCSetPropertyAction *SCApp::sAction = nil;
-
- const ResIDT kScriptsMenuID = 140;
-
- void main(void)
- {
- // Set Debugging options
- #ifdef Debug_Throw
- gDebugThrow = debugAction_SourceDebugger; // or debugAction_SourceDebugger
- #endif
-
- #ifdef Debug_Signal
- gDebugSignal = debugAction_SourceDebugger;
- #endif
-
- InitializeHeap(4);
- UQDGlobals::InitializeToolbox(&qd);
-
- SCApp theApp;
- theApp.Run();
- }
-
- SCApp::SCApp()
- {
- // get spec for the Scripts Folder
- FSSpec appSpec;
- long folderID;
-
- UFinder::GetAppSpec(appSpec);
- folderID = UFinder::GetFolderID(appSpec,"\pScript Menu Items");
-
- // attach a new handler for the scripts menu
- AddAttachment(new SCScriptsMenuHandler(kScriptsMenuID,appSpec.vRefNum,folderID));
- }
-
-
- void
- SCApp::StartUp()
- {
- new SCDoc(this);
- }
-
- long
- SCApp::GenerateUniqueID()
- {
- return ++sUniqueID;
- }
-
- // note: we can't use LSemanticUndoer for its PostAction, ObeyCommand, and FindCommandStatus
- // because LSemanticUndoer has no provision for getting an Undo string from any place but a
- // STR# resource, and we are constructing strings from the 'aete' properties.
- // this code below is mostly copied from LSemanticUndoer, but changed to ease this restriction
-
- // in a real application, you would define a more general class than SCSetPropertyAction
- // and be able to Post all actions of that class
-
- void
- SCApp::PostAction(SCSetPropertyAction *inAction)
- {
- delete sAction;
- sAction = inAction;
- sAction->Redo();
- }
-
- Boolean
- SCApp::ObeyCommand(
- CommandT inCommand,
- void *ioParam)
- {
- switch (inCommand) {
-
- case cmd_Undo:
- Assert_(sAction);
- if (sAction->CanRedo() || sAction->CanUndo()) {
- if (sAction->CanUndo())
- sAction->Undo();
- else
- sAction->Redo();
- }
- return true;
- break;
-
- default:
- return inherited::ObeyCommand(inCommand, ioParam);
- break;
- }
- return false;
- }
-
- void
- SCApp::FindCommandStatus(
- CommandT inCommand,
- Boolean &outEnabled,
- Boolean &outUsesMark,
- Char16 &outMark,
- Str255 outName)
- {
- switch (inCommand) {
-
- case cmd_Undo:
- outEnabled = false;
- if (sAction) {
- Str255 prop;
- if (sAction->CanRedo()) {
- outEnabled = true;
- CopyPStr("\pRedo ",outName);
- sAction->GetDescriptor(prop);
- ConcatPStr(outName,prop);
- } else if (sAction->CanUndo()) {
- outEnabled = true;
- CopyPStr("\pUndo ",outName);
- sAction->GetDescriptor(prop);
- ConcatPStr(outName,prop);
- }
- }
-
- if (!outEnabled) {
- GetIndString(outName, STRx_Standards, str_CantUndo);
- ThrowIfResError_();
- }
- break;
-
- default:
- inherited::FindCommandStatus(inCommand, outEnabled, outUsesMark, outMark, outName);
- break;
-
- }
- }
-